﻿using Customer.API.Applcation.Command.CusContactCommand;
using Customer.Domain;
using Customer.Infrstructre.CusContactManager;
using MediatR;
using System.Diagnostics.Contracts;

namespace Customer.API.Applcation.CommandHandlers.CusContactCommandHandler
{
    /// <summary>
    /// 客户联系人添加
    /// </summary>
    public class CusContactCreateCommandHandler:IRequestHandler<CusContactCreateCommand,int>
    {
        private readonly ICusContactRepository _cusContactRep;
        public CusContactCreateCommandHandler(ICusContactRepository _cusContactRep)
        {
            this._cusContactRep = _cusContactRep;
        }

        public async Task<int> Handle(CusContactCreateCommand request, CancellationToken cancellationToken)
        {
            var res = new CusContact() { Ccontact = request.Ccontact, Caddress = request.Caddress, Cphone = request.Cphone, CreatTime = request.CreatTime, Office_Id = request.Office_Id, User_Id = request.User_Id, AddName = request.AddName, AddTime = request.AddTime };
            return await _cusContactRep.AddAsync(res);
        }
    }
}
